var xhr;
var flag0=false;
var flag1=false;
var flag2=false;
var flag3=false;

function getName(){
    var username = document.getElementById("username").value;
    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = processPsd;
    xhr.open("GET","/account/checkUser?username="+username,true);
    xhr.send(null);
}

function processPsd(){
    var password = document.getElementById("password").value;
    var l=password.length;
    if(xhr.readyState == 4){
        if(xhr.status == 200){
            var responseInfo = xhr.responseText;
            if(responseInfo == "Not Exist" && password!=""){
                comparePwd(password,l);

                if(flag0){
                    document.getElementById("isRightInfo").src =
                        "../images/short.png" ;
                }
                else if(flag1 && flag2 && flag3){//判断中强弱的
                    document.getElementById("isRightInfo").src =
                        "../images/l.png" ;
                }else if(flag1&&flag2 ||flag1&&flag3 ||flag3&&flag2){
                    document.getElementById("isRightInfo").src =
                        "../images/m.png" ;
                }else {
                    document.getElementById("isRightInfo").src =
                        "../images/s.png" ;
                }

            }
            else if(responseInfo =="Exist"){
                document.getElementById("isRightInfo").src =
                    "../images/error.png" ;
            }
            flag1=flag2=flag3=flag0=false;

        }
    }
}
function comparePwd(password,l) {
    if (l < 6&& l>=0) {
        flag0=true;
    }
else
    {
        for(var i=0;i<l;i++) {

            var code = password.charCodeAt(i);
            if ((code >= 65 && code <= 90)||(code >= 97 && code <= 122)) {
                //有字母
                flag1=true;
            }
            else if (code >= 48 && code <= 57) {
                //有数字
                flag2 = true;
            }
            else if ((code >= 33 && code <= 47)||(code >= 58 && code <= 64)||(code >= 91 && code <= 96)) {
                flag3 = true;
            }
        }
    }
}